//1.状态模式定义
class  SuccessSate{
    show() {
        console.log('显示绿色');
    }
}
class  WarningState{
    show() {
        console.log('显示黄色');
    }
}
class  ErroeState{
    show() {
        console.log('显示红色');
    }
}
class Battery {
    constructor(){
        this.amout = 'high';
        this.state = new SuccessSate();
    };
    show() {
        this.state && this.state.show();
        if(this.amout == 'high') {
            this.amout = 'middle';
            this.state = new WarningState();
        }
        else if(this.amout == 'middle') {
            this.amout = 'low';
            this.state = new ErroeState();
        }
        else if(this.amout == 'low') {
            this.state = '';
        }
        else {
            console.log('没电了')
        }
    }
};

let battery = new Battery();
battery.show();
battery.show();
battery.show();
battery.show();